package com.alg.pattern.chain;
/**
 * @ClassName AbstractLogger
 * @Author Jiayi Zheng
 * @Date 2022/12/30 11:04
 * @Description: todo
 * @Version V1.0
 */

public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;

    //责任链中的下一个元素
    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger){
        this.nextLogger = nextLogger;
    }

    public void logMessage(int level, String message){

        // 如果级别小等于当前级别 打印日志
        if(this.level <= level){
            write(message);
        }

        // 交给下一个接收器处理
        if(nextLogger !=null){
            nextLogger.logMessage(level, message);
        }
    }

    abstract protected void write(String message);

}

